function Ankhy_Mage_2()

    ------------------
	-- Cast Power Word: Fortitude
	ccrCastBuffIfMissing("Molten Armor")
	 ---------------------
	 -- Cast Inner Fire
	ccrCastBuffIfMissing("Arcane Brilliance")
	 ---------------------
	-- Autoaccept LFR invite
	AcceptProposal();
	--------------------------
	if ccrPlayerIsCastingOrChanneling() then return end
	
	
		-- Invoker's Energy
		
		if not ccrPlayerHasBuff("Alter Time") then	
			if not ccrPlayerHasBuff("Invoker's Energy") and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
			if ccrPlayerMana() < 20 and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
			if not onCD("Alter Time") and ccrPlayerHasBuff("Invoker's Energy") and ccrUnitBuffDuration("player", "Invoker's Energy") <= 6 and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
		end	
		
		-- Is in combat
		
		if ccrPlayerIsInCombat() then
		
			-- Survival
			
			if ccrPlayerHealth() <= 20
				and SpellIsReady("Ice Block")
					then
					SpellStopCasting()
					ccrCast("Ice Block")
					return
			else
				if ccrPlayerHasBuff("Ice Block") and ccrPlayerHealth() >= 20
					then
					CancelUnitBuff("player", "Ice Block")
					return
				end
			end
		
			-- Interrupt
		
			if ccrSpellCanAttack("Counterspell")
				and ccrTargetIsCastingOrChanneling()
				and ccrTargetIsInteruptable()
				and ccrTargetHasLeftOnCast(1)
					then
					ccrCastAttack("Counterspell")
					return
			end	
		
			--Thok Stopcasting
			
			if ccrTargetName("Thok the Bloodthirsty")
				and ccrTargetIsCastingSpell("Deafening Screech")
				then
				SpellStopCasting()
				return
			end
					
			-- Mirror Image
			
			if SpellIsReady("Mirror Image") and ccrTargetIsBoss()
				and not ccrPlayerIsCastingSpell("Evocation")
				then
				ccrCast("Mirror Image")
				return
			end

		
			-- Combustion
			
			local vIgnite = select(15, UnitAura("target", "Ignite", nil, "PLAYER HARMFUL"))
			 if vIgnite ~= nil and vIgnite > 135000 and SpellIsReady("Combustion") and ccrTargetIsBoss() then
				SpellStopCasting()
				ccrCastAttack("Combustion")
				return
			end

			-- Alter Time
			
			if ccrPlayerHasBuff("Pyroblast!") and ccrPlayerHasBuff("Heating Up") and ccrPlayerHasBuff("Invoker's Energy") and SpellIsReady("Combustion") and SpellIsReady("Presence of Mind") and SpellIsReady("Alter Time")	and ccrTargetIsBoss()
				then
					ccrCast("Alter Time")
				return
			else
				if ccrPlayerHasBuff("Alter Time") and not ccrPlayerHasBuff("Heating Up") and not ccrPlayerHasBuff("Pyroblast!") and onCD("Presence of Mind")
					then
					ccrCast("Alter Time")
					return
				end
			end
			
			-- Presence Of time
			if ccrPlayerHasBuff("Alter Time")
				and SpellIsReady("Presence of Mind")
					then
					ccrCastAttack("Presence of Mind")
					return
				else
				if ccrPlayerHasBuff("Pyroblast!") and SpellIsReady("Combustion") and onCD("Alter Time")
					and SpellIsReady("Presence of Mind")
					then
					ccrCastAttack("Presence of Mind")
					return
				end
			end	
	

		
			-- AOE
			if ccrTargetHasMyDebuff("Combustion") and ccrTargetCount(5) >= 3 and SpellIsReady("Inferno Blast")
				then
				ccrCastAttack("Inferno Blast")
				return
			else
				if (ccrTargetCount(7) >= 3 and SpellIsReady("Inferno Blast"))
					then
					ccrCastAttack("Inferno Blast")
					return
			else
					if (SpellIsReady("Cone of Cold") and ccR_HostilesNearPlayer(10) >= 3 and ccrPlayerIsFacingTarget())
								then
								ccrCastAttack("Cone of Cold")
								return
			else
						if ccR_HostilesNearPlayer(10) > 6
							then
							ccrCast("Arcane Explosion")
							return
			else
							if ccR_Mage_CheckForMissingBomb()
								then
									ccR_Mage_ApplyMissingBomb() 
								return
							end
						end
					end
				end									
			end


			-- If moving
		if ccrPlayerIsFacingTarget() then	
			if ccrPlayerIsMoving() then
				if ccrPlayerHasBuff("Pyroblast!")
					then
					ccrCastAttack("Pyroblast")
					return
				else
					if SpellIsReady("Scorch")
						then
						ccrCastAttack("Scorch")
						return
					end
				end
			end
		end	
			
			--If not in raid
			
			if PlayerIsSOLO() then
				if not ccrPlayerHasBuff("Ice Barrier") and not ccrTargetName("Raider's Training Dummy")
					then
					ccrCastAttack("Ice Barrier")
					return
				end
				if  ccR_HostilesNearPlayer(10) > 1 and SpellIsReady("Frost Nova")
					then
					ccrCastAttack("Frost Nova")
					return
				else
					if SpellIsReady("Cone of Cold") and  ccR_HostilesNearPlayer(10) > 1 and ccrPlayerIsFacingTarget()
						then
						ccrCastAttack("Cone of Cold")
						return
					end
				end
			end
			
			
		if ccrPlayerIsFacingTarget() then
			-- Rotation
			if ccrPlayerHasBuff("Presence of Mind")
				then
					ccrCastAttack("Pyroblast")
					return
			else
				if (ccrPlayerHasBuff("Pyroblast!") and onCD("Alter Time")) or (ccrPlayerHasBuff("Alter Time") and ccrPlayerHasBuff("Pyroblast!")) or (ccrPlayerHasBuff("Pyroblast!") and onCD("Combustion"))
					then
						ccrCastAttack("Pyroblast")
					return
				else
					if ccrPlayerHasBuff("Pyroblast!") and not ccrTargetIsBoss()
						then
							ccrCastAttack("Pyroblast")
							return
					else
						if ccrPlayerHasBuff("Pyroblast!") and ccrUnitBuffDuration("player", "Pyroblast!") <= 0.1
							then SpellStopCasting()
								ccrCastAttack("Pyroblast")
								return
						else
							if ccrPlayerHasBuff("Heating Up") and SpellIsReady("Inferno Blast") or (ccrPlayerHasBuff("Pyroblast!") and not ccrPlayerHasBuff("Heating Up"))
								and SpellIsReady("Inferno Blast")
								then
									ccrCastAttack("Inferno Blast")
								return
							else
								if not (ccrTargetHasMyDebuff("Living Bomb") or ccrTargetHasMyDebuff("Nether Tempest") or ccrTargetHasMyDebuff("Frost Bomb"))
									and SpellIsReady("Mage Bomb")
									then
										ccrCastAttack("Mage Bomb")
									return
								else
									if SpellIsReady("Fireball") and not ccrPlayerHasBuff("Presence of Mind") and not (ccrTargetName("Thok the Bloodthirsty") and ccrTargetHasBuff("Acceleration"))
										then
											ccrCastAttack("Fireball")
										return
									else
										if SpellIsReady("Scorch") and ccrTargetName("Thok the Bloodthirsty")
											then
												ccrCastAttack("Scorch")
											return
										end	
									end
								end
							end	
						end
					end
				end
			end
		end	
	end	
end
